package com.shihang.crm.web.action;

import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;
import com.opensymphony.xwork2.ModelDriven;
import com.shihang.crm.bean.User;
import com.shihang.crm.service.UserService;

public class UserAction extends ActionSupport implements ModelDriven<User> {
    private User user = new User();
    private UserService userService;

    public void setUserService(UserService userService) {
        this.userService = userService;
    }

    public String login() throws Exception{
        //1调用service执行登录逻辑
        //2将返回的User对象放入session域
        //3重定向到项目首页
        Object code =  ActionContext.getContext().getParameters().get("user_code");
        User u = userService.getUserByPassword(this.user);
        ActionContext.getContext().getSession().put("user",u);
        return "toHome";
    }

    @Override
    public User getModel() {
        return user;
    }
}
